# -*- coding: utf-8 -*-
# !/usr/bin/env python
"""
-------------------------------------------------
   File Name：     convert2gif
   Description :   
   Author :       lth
   date：          2022/12/7
-------------------------------------------------
   Change Activity:
                   2022/12/7 18:59: create this script
-------------------------------------------------
this script is used to make the gif from a dir
"""
__author__ = 'lth'

import os

import imageio


def create_gif(img_dir, image_list, gif_name, duration=5):
    frames = []
    for image_name in image_list:
        print("image_name={0} img_dir={1}".format(image_name, img_dir))
        frames.append(imageio.imread(img_dir + '/' + image_name))
    imageio.mimsave(gif_name, frames, 'GIF', duration=duration)
    return


def main():
    img_dir = './to2gif'
    duration = 0.1  # 每秒20帧
    image_list = sorted(os.listdir(img_dir + '/'))
    gif_name = 'nerf.gif'
    create_gif(img_dir, image_list, gif_name, duration)


if __name__ == '__main__':
    main()
